import request from '@/utils/request'
import {
  PasswordLogin,
  CodeLogin,
  Register,
  Pagenate,
  ScenicList,
  UpdateUserInfo,
  PublishDynamic,
  CommentList,
  PostComment
} from '@/types'

// 密码登录
export const passwordLogin = (data: PasswordLogin) => {
  return request<any>('/user/login', 'POST', data)
}

// 验证码登录
export const codeLogin = (data: CodeLogin) => {
  return request<any>('/user/code', 'POST', data)
}

// 校验手机号是否注册
export const validPhone = (phone: string) => {
  return request<any>(`/user/valid/${phone}`, 'GET')
}

// 用户注册
export const register = (data: Register) => {
  return request<any>('/user/register', 'POST', data)
}

// 发送验证码
export const sendCode = (phone: string) => {
  return request<any>('/user/sendCode', 'POST', { phone })
}

// 获取景区列表
export const getScenicList = (data: ScenicList) => {
  return request<any>('/admin/scenic/list', 'POST', data)
}

// 获取景区详情
export const getScenicDetail = (id: string) => {
  return request<any>(`/admin/scenic/${id}`, 'GET')
}

// 收藏景区
export const collectScenic = (id: string) => {
  return request<any>(`/user/collect/${id}`, 'GET')
}

// 获取用户信息
export const getUserInfo = () => {
  return request<any>('/user', 'GET')
}

// 修改用户信息
export const updateUserInfo = (data: UpdateUserInfo) => {
  return request<any>('/user/update', 'PUT', data)
}

// 上传头像
export const uploadAvatar = (data: FormData) => {
  return request<any>('/upload/1', 'POST', data)
}

// 获取动态列表
export const getDynamicList = (data: ScenicList) => {
  return request<any>('/admin/community/list', 'POST', data)
}

// 获取动态详情
export const getDynamicDetail = (id: string) => {
  return request<any>(`/admin/community/${id}`, 'GET')
}

// 动态点赞
export const dynamicLike = (id: string) => {
  return request<any>(`/user/star/${id}`, 'GET')
}

// 删除动态
export const deleteDynamic = (id: string) => {
  return request<any>(`/user/dynamic/${id}`, 'DELETE')
}

// 上传动态图片
export const uploadDynamicPic = (data: FormData) => {
  return request<any>('/upload/3', 'POST', data)
}

// 发表动态
export const publishDynamic = (data: PublishDynamic) => {
  return request<any>('/user/publish', 'POST', data)
}

// 删除动态图片
export const deleteDynamicPic = (imgs: string[]) => {
  return request<any>('/upload', 'DELETE', { imgs })
}

// 我赞过的动态
export const getStarDynamic = (data: Pagenate) => {
  return request<any>('/user/getStar', 'POST', data)
}

// 我收藏的景区
export const getCollectScenic = (data: Pagenate) => {
  return request<any>('/user/getCollect', 'POST', data)
}

// 获取评论列表
export const getCommentList = (data: CommentList) => {
  return request<any>('/user/comment', 'POST', data)
}

// 发表评论
export const postComment = (data: PostComment) => {
  return request<any>('/user/postComment', 'POST', data)
}
